<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="68px">
        <el-form-item label="用户类型" prop="queryType">
          <el-select
            class="query-el-input-width"
            v-model="queryParams.queryType"
            placeholder="请选择"
            clearable
          >
            <el-option
              v-for="item in totalList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              class="query-el-input-width"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="客户姓名" prop="nameNike">
          <el-input
            v-model="queryParams.nameNick"
            placeholder="客户姓名"
            clearable
          />
        </el-form-item>
        <el-form-item label="时间选项" prop="dateRange">
          <el-date-picker
            clearable
            v-model="dateRange"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="YYYY-MM-DD"
            />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="Download"
            @click="handleExport"
            v-hasPermi="['business:checkIn:export']"
          >导出</el-button>
        </el-col>
      </el-row>
  
      <el-table v-loading="loading" :data="aiRequestRecordsList">
        <el-table-column label="使用时间" align="center" prop="lifeTime" />
        <el-table-column label="客户昵称" align="center" prop="nameNick" />
        <el-table-column label="注册地址" align="center" prop="registeredAddress" />
        <el-table-column label="手机型号" align="center" prop="phoneModel" />
        <el-table-column label="注册时间" align="center" prop="registeredTime" />
        <el-table-column label="手机号" align="center" prop="phone" >
          <template #default="scope">
            {{ scope.row.phone.replace(/^(\d{3})\d{4}(\d{4})$/, '$1****$2') }}
          </template>
        </el-table-column>
        <el-table-column label="调用素材类型名称" align="center" prop="materialName" />
        <el-table-column label="是否点击门店按钮" align="center" prop="isShopButton" />
        <el-table-column label="是否预约门店" align="center" prop="isSubscribe" />
        <el-table-column label="是否是销售转发" align="center" prop="isSalesForward" />
      </el-table>
  
      <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
</template>

<script setup name="CustomerPreferenceAnalysis">
import {getAiPreferenceUsageDataListApi} from "@/api/system/aiRequestRecords";

const { proxy } = getCurrentInstance();
const aiRequestRecordsList = ref([]);
const loading = ref(true);
const total = ref(0);
const dateRange = ref([]);
const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    queryType:'1',
    nameNick:undefined,
    startTime:undefined,
    endTime:undefined,
  },
});
const totalList = ref([{label: '全部',value: '1'},{label: '纯用户', value: '2'}]);

const { queryParams } = toRefs(data);

function getList() {
    loading.value = true;
    let list = JSON.parse(JSON.stringify(queryParams.value))
    if(dateRange.value && dateRange.value.length>0){
      list.startTime = dateRange.value[0]
      list.endTime = dateRange.value[1]
    }
    getAiPreferenceUsageDataListApi(list).then(response => {
        aiRequestRecordsList.value = response.rows;
        total.value = response.total;
        loading.value = false;
    });
}


function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
}

/** 重置按钮操作 */
function resetQuery() {
    proxy.resetForm("queryRef");
    dateRange.value = []
    handleQuery();
}
function handleExport() {
  let list = JSON.parse(JSON.stringify(queryParams.value))
  if(dateRange.value && dateRange.value.length>0){
    list.startTime = dateRange.value[0]
    list.endTime = dateRange.value[1]
  }
  proxy.download('business/aiSendRecords/getAiPreferenceUsageDataListExport', {
    ...list
  }, `customerPreferenceAnalysis_${new Date().getTime()}.xlsx`)
}
getList();

</script>
<style lang="scss" scoped>

</style>
